package game.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.controller.base.BaseController;
import common.model.enums.ClassificationTypeEnum;
import common.model.po.GBlueprint;
import common.model.po.GBlueprintAuthor;
import common.model.po.GClassification;
import common.model.request.base.PaginationRequest;
import common.model.response.base.Result;
import game.model.request.SearchBlueprintRequest;
import game.model.request.SaveBlueprintRequest;
import game.model.vo.BlueprintVo;
import game.service.GBlueprintAuthorService;
import game.service.GBlueprintService;
import game.service.GClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 前端控制器
 *
 * @author 米泽鹏
 * @since 2024-08-17 下午 03:13
 */
@Api(tags = "蓝图管理")
@RestController
@RequestMapping("/game/g-blueprint")
public class GBlueprintController extends BaseController {

	@Resource
	private GBlueprintService service;
	@Resource
	private GClassificationService classificationService;
	@Resource
	private GBlueprintAuthorService blueprintAuthorService;

	@ApiOperation(value = "蓝图分页查询", notes = "蓝图分页查询")
	@PostMapping("/readOnly/searchBlueprintByPage")
	public Result<Page<BlueprintVo>> searchBlueprintByPage(@ApiParam(value = "分页查询请求", required = true) @RequestBody @Validated PaginationRequest<SearchBlueprintRequest, GBlueprint> paginationRequest) {
		return successWithData(service.searchBlueprintByPage(paginationRequest));
	}

	@ApiOperation(value = "获取所有蓝图的类别", notes = "获取所有蓝图的类别")
	@GetMapping("/readOnly/getAllBlueprintClassification")
	public Result<List<GClassification>> getAllBlueprintClassification() {
		return successWithData(classificationService.lambdaQuery().eq(GClassification::getType, ClassificationTypeEnum.BLUEPRINT).list());
	}

	@ApiOperation(value = "获取所有蓝图的作者", notes = "获取所有蓝图的作者")
	@GetMapping("/readOnly/getAllBlueprintAuthor")
	public Result<List<GBlueprintAuthor>> getAllBlueprintAuthor() {
		return successWithData(blueprintAuthorService.list());
	}

	@ApiOperation(value = "蓝图保存", notes = "蓝图保存")
	@PostMapping("/saveBlueprint")
	public Result<?> saveBlueprint(@ApiParam(value = "蓝图保存请求", required = true) @RequestBody @Validated SaveBlueprintRequest request) {
		return service.saveBlueprint(request);
	}

	@ApiOperation(value = "蓝图删除", notes = "蓝图删除")
	@DeleteMapping("/deleteBlueprint/{id}")
	public Result<?> deleteBlueprint(@ApiParam(value = "建筑id", required = true) @PathVariable Long id) {
		return service.deleteBlueprint(id);
	}

}
